<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style type="text/css">
        .divForm {
            position: absolute; /*绝对定位*/
            width: 300px;
            height: 200px;

            border: 1px solid #595fff;
            text-align: center; /*(让div中的内容居中)*/
            top: 50%;
            left: 50%;
            margin-top: -200px;
            margin-left: -150px;
        }
    </style>
</head>
<body>
<div class="divForm">
    <form id="upload-form" action="/book-converter" method="post" enctype="multipart/form-data">
        <input type="file" id="upload" name="upload"/> <br/>
        <input type="submit" value="Upload"/>
    </form>
</div>
</body>
<script>
    form.on('submit', function () {
        // 此处进行ajax上传
        // 检查是否支持FormData
        if (window.FormData) {
            var formData = new FormData();

            // 建立一个upload表单项，值为上传的文件
            formData.append('upload', document.getElementById('upload').files[0]);
            var xhr = new XMLHttpRequest();
            xhr.open('POST', $(this).attr('action'));
            // 定义上传完成后的回调函数
            xhr.onload = function () {
                if (xhr.status === 200) {
                    console.log('上传成功');
                } else {
                    console.log('出错了');
                }
            };
            xhr.send(formData);
        }
    });
</script>
</html>